package pre.bookcloud.java21.chapter3;

public class TestAnnotaion {
  @interface MyAnno {
    String name();

    int age();
  }

  @MyAnno(name = "张三", age = 18)
  public void test() {}

  public static void main(String[] args) {
    // 获取序号为1的枚举
    System.out.println(Color.getColorName(1));
  }
}

enum Color {
  RED(1, "红色"),
  GREEN(2, "绿色"),
  BLUE(3, "蓝色");

  private int code;
  private String name;

  Color(int code, String name) {
    this.code = code;
    this.name = name;
  }

  // 通过序号获取枚举
  public static String getColorName(int code) {
    for (Color color : Color.values()) {
      if (color.code == code) {
        return color.name;
      }
    }
    return null;
  }
}
